package com.f5.management.controller;

import com.f5.management.entity.Building;
import com.f5.management.entity.RealEstate;
import com.f5.management.entity.dto.RealEstateUserDto;
import com.f5.management.service.BuildingService;
import com.f5.management.service.RealEstateService;
import com.f5.management.utils.PageResult;
import com.f5.management.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 房产管理
 */

@RestController
@RequestMapping("/realEstate")
@CrossOrigin(origins = {"http://localhost:8080", "null"})
public class RealEstateController {
    @Autowired
    private RealEstateService realEstateService;

    //添加信息
    @RequestMapping("/add")
	public ResponseResult<Integer> add(RealEstateUserDto realEstateUserDto) {
		int reData = realEstateService.add(realEstateUserDto);
		return new ResponseResult<Integer>(true).setData(reData);
	}
	//更改信息
	@RequestMapping("/updateInfo")
	public ResponseResult<String> updateInfo(RealEstateUserDto realEstateUserDto) {

		return new ResponseResult<String>(realEstateService.updateInfo(realEstateUserDto));

	}
	//查询编号是否存在
	@RequestMapping("/selectNumber")
	public ResponseResult<String> selectNumber(String serialNumber){
		return new ResponseResult<String>(realEstateService.selectNumber(serialNumber));
	};
	//删除信息
	@RequestMapping("/delInfo")
	public ResponseResult<String> delInfo(int id) {

		return new ResponseResult<String>(realEstateService.delInfo(id));

	}
    //分页展示信息
    @RequestMapping("/findByPage")
    public PageResult<List<RealEstateUserDto>> findByPage(int page, int size) {

        return realEstateService.findByPage(page, size);
    }
    //id查询数据进行修改
   @RequestMapping("/findById")
	public ResponseResult<RealEstateUserDto> findById(int id) {
       RealEstateUserDto realEstateUserDto = realEstateService.findById(id);
	return new ResponseResult<RealEstateUserDto>(true).setData(realEstateUserDto);
	}
	//通过编号查找信息
	@RequestMapping("/findByNumber")
	public PageResult<List<RealEstateUserDto>> findByNumber(String serialNumber,int rid, int page) {
		//调用service方法查询数据
		PageResult<List<RealEstateUserDto>> result = realEstateService.findByNumber(serialNumber, rid,page, 10);
		return result;
	}
}

















